Skip to main content

unity 加载 FairyGUI的生成文件

unity 加载 FairyGUI的生成文件

前提

unity3d 要下载 FairyGUI 插件

加载方式

1. 使用UI pancel

  1. 右键 FairyGUI-> UI pancel 点击 Component Name 选择组件进行加载

2. 脚本的方式加载

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;

public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GRoot.inst.SetContentScaleFactor(800, 600);
UIPackage.AddPackage("FGUI/Package1");
GComponent component = UIPackage.CreateObject("Package1", "Component1").asCom;
GRoot.inst.AddChild(component);
}

// Update is called once per frame
void Update()
{

}
}

3. 混合使用——半UI pancel,半脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;

public class fairyGUI2 : MonoBehaviour
{
private GComponent mainUI;
private GComponent booCom;
// Start is called before the first frame update
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
booCom = UIPackage.CreateObject("Package1", "Component3").asCom;
mainUI.GetChild("n3").onClick.Add(()=> { PlayUI(booCom); });

}

// Update is called once per frame
void Update()
{
}

void PlayUI(GComponent targetCom)
{
mainUI.GetChild("n3").visible = false;
GRoot.inst.AddChild(targetCom);
Transition t = targetCom.GetTransition("t1");
t.Play();
Debug.Log("aaaaaaa");
}
}